<template>
  <div class="create-post-container">
    <el-form ref="postForm" :model="postForm" :rules="rules" label-position="top" label-width="100px" class="meeting-form">
      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-divider content-position="left">基本信息</el-divider>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-form-item label="会议标题" prop="meetingtitle">
            <el-input v-model="postForm.meetingtitle" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-form-item label="讲师姓名" prop="lecturerName">
            <el-select
              v-model="postForm.lecturerName"
              multiple
              filterable
              allow-create
              default-first-option
              placeholder="可自行输入，并按下回车选择讲师"
              style="width:100%"
            >
              <el-option
                v-for="(item, index) in postForm.lecturerName"
                :key="index"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="9" :offset="3">
          <el-form-item label="会议类型" prop="type">
            <el-select
              v-model="postForm.type"
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                v-for="item in meetingTypeOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <el-form-item label="参会类型" prop="meetingtype">
            <el-select
              v-model="postForm.meetingtype"
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                v-for="item in joinMeetingTypeOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="9" :offset="3">
          <el-form-item label="会议CODE" prop="meetingcode">
            <el-input v-model="postForm.meetingcode" />
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <el-form-item label="OM编码" prop="omcode">
            <el-input v-model="postForm.omcode" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="9" :offset="3">
          <el-form-item label="会议起止时间" prop="dateRange">
            <el-date-picker
              v-model="postForm.dateRange"
              type="datetimerange"
              start-placeholder="召开时间"
              end-placeholder="结束时间"
              :default-time="['12:00:00']"
              value-format="yyyy-MM-dd HH:mm:ss"
              style="width:100%"
              @change="dateRangeChange"
            />
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <el-form-item label="实际会议时间" prop="actualDateRange">
            <el-date-picker
              v-model="postForm.actualDateRange"
              type="datetimerange"
              start-placeholder="召开时间"
              end-placeholder="结束时间"
              :default-time="['12:00:00']"
              value-format="yyyy-MM-dd HH:mm:ss"
              style="width:100%"
              @change="actualDateRangeChange"
            />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="9" :offset="3">
          <el-form-item label="省份" prop="provinceCode" :required="isCityMeeting">
            <el-select
              v-model="postForm.provinceCode"
              filterable
              clearable
              placeholder="请选择"
              style="width:100%"
              @change="changeProvince"
            >
              <el-option
                v-for="item in provinceOptions"
                :key="item.id"
                :label="item.province_name"
                :value="item.province_code"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <el-form-item label="城市" prop="cityCode" :required="isCityMeeting">
            <el-select
              v-model="postForm.cityCode"
              filterable
              clearable
              placeholder="请选择"
              style="width:100%"
              @change="changeCity"
            >
              <el-option
                v-for="item in cityOptions"
                :key="item.id"
                :label="item.city_name"
                :value="item.city_code"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-form-item label="召开地点" prop="location">
            <el-input v-model="postForm.location" />
          </el-form-item>
        </el-col>
      </el-row>

      <!-- <el-row :gutter="20">
        <el-col :span="9" :offset="3">
          <el-form-item label="所属会议" prop="parentmeetingid">
            <el-select
              v-model="postForm.parentmeetingid"
              clearable
              filterable
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                v-for="item in parentMeetingOptions"
                :key="item.id"
                :label="item.meetingtitle"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <el-form-item label="关联会议" prop="relatedmeetingid">
            <el-select
              v-model="postForm.relatedmeetingid"
              clearable
              filterable
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                v-for="item in relatedMeetingOptions"
                :key="item.id"
                :label="item.meetingtitle"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row> -->

      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-form-item label="会议直播" prop="livebroadcastid" :required="isBroadcastMeeting">
            <el-select
              v-model="postForm.livebroadcastid"
              filterable
              clearable
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                v-for="item in broadcastsOptions"
                :key="item.id"
                :label="item.title"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-form-item label="BU" prop="buids">
            <el-select
              v-model="postForm.buids"
              multiple
              filterable
              placeholder="可多选"
              style="width:100%"
            >
              <el-option
                v-for="item in buListOptions"
                :key="item.id"
                :label="item.bu"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-form-item label="TA" prop="taids">
            <el-select
              v-model="postForm.taids"
              multiple
              filterable
              placeholder="可多选"
              style="width:100%"
            >
              <el-option
                v-for="item in taListOptions"
                :key="item.id"
                :label="item.ta"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-form-item label="相关产品（代表可见）" prop="brandids">
            <el-select
              v-model="postForm.brandids"
              multiple
              filterable
              placeholder="可多选"
              style="width:100%"
            >
              <el-option
                v-for="item in productsOptions"
                :key="item.id"
                :label="item.brand"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-form-item label="目标科室（医生可见）" prop="departids">
            <el-select
              v-model="postForm.departids"
              multiple
              filterable
              placeholder="可多选"
              style="width:100%"
            >
              <el-option
                v-for="item in deparpmentOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-form-item label="测试用户组" prop="userTypeids">
            <el-select
              v-model="postForm.userTypeids"
              multiple
              filterable
              placeholder="可多选"
              style="width:100%"
            >
              <el-option
                v-for="item in userTypeOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                :disabled="item.name !== 'MCM' && item.name !== 'Lankr'"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="15" :offset="3">
          <el-form-item label="活动页面地址" prop="thirdUrl" :required="checkThirdPage">
            <el-input v-model="postForm.thirdUrl" />
            <div class="form-tips text-warning">以 http:// 或 https:// 开始，用于会议详情页展示外部H5页面。</div>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="展示活动页面" prop="isThird" class="text-center">
            <el-switch v-model="postForm.isThird" :active-value="1" :inactive-value="0" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-form-item label="会议简介" prop="meetingdesc">
            <el-input v-model="postForm.meetingdesc" type="textarea" rows="4" />
            <div class="form-tips text-warning">用于分享描述</div>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-form-item label="直播日程" prop="livebroadcastschedule">
            <vue-ueditor-wrap v-model="postForm.livebroadcastschedule" :config="ueditorConfig" />
          </el-form-item>
        </el-col>
      </el-row> -->

      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-divider content-position="left">相关图片</el-divider>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="9" :offset="3">
          <el-form-item label="会议封面" prop="coverurl">
            <el-upload
              v-if="coverList < 1"
              :action="uploadUrl"
              :multiple="false"
              :limit="1"
              name="fies"
              :headers="{token}"
              :on-success="handleUploadSucc"
              :show-file-list="false"
              drag
              accept="image/jpeg,image/png,image/gif"
              class="drag-upload-wrapper"
            >
              <i class="el-icon-upload" />
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            </el-upload>

            <ul v-else class="thumb-img-list">
              <li
                v-for="(item, index) in coverList"
                :key="index"
                class="item"
              >
                <img :src="item.url" :alt="item.name" class="img">
                <div
                  class="el-icon-close close-btn"
                  title="点击可删除"
                  @click="handleUploadRemove(item)"
                />
              </li>
            </ul>
            <div class="form-tips text-warning">建议尺寸：750x320，或同比例尺寸</div>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <el-form-item label="会议背景图" prop="backgroundpictureurl">
            <el-upload
              v-if="backgroundList < 1"
              :action="uploadUrl"
              :multiple="false"
              :limit="1"
              name="fies"
              :headers="{token}"
              :on-success="handleBgUploadSucc"
              :show-file-list="false"
              drag
              accept="image/jpeg,image/png,image/gif"
              class="drag-upload-wrapper"
            >
              <i class="el-icon-upload" />
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            </el-upload>

            <ul v-else class="thumb-img-list">
              <li
                v-for="(item, index) in backgroundList"
                :key="index"
                class="item"
              >
                <img :src="item.url" :alt="item.name" class="img">
                <div
                  class="el-icon-close close-btn"
                  title="点击可删除"
                  @click="handleBgUploadRemove(item)"
                />
              </li>
            </ul>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="9" :offset="3">
          <el-form-item label="分享图标" prop="icon">
            <el-upload
              v-if="iconList < 1"
              :action="uploadUrl"
              :multiple="false"
              :limit="1"
              name="fies"
              :headers="{token}"
              :on-success="handleIconUploadSucc"
              :show-file-list="false"
              drag
              accept="image/jpeg,image/png,image/gif"
              class="drag-upload-wrapper"
            >
              <i class="el-icon-upload" />
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            </el-upload>

            <ul v-else class="thumb-img-list">
              <li
                v-for="(item, index) in iconList"
                :key="index"
                class="item"
              >
                <img :src="item.url" :alt="item.name" class="img">
                <div
                  class="el-icon-close close-btn"
                  title="点击可删除"
                  @click="handleIconUploadRemove(item)"
                />
              </li>
            </ul>
            <div class="form-tips text-warning">建议尺寸：200x200，或同比例尺寸</div>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="18" :offset="3">
          <el-divider content-position="left">相关操作</el-divider>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="2" :offset="3">
          <el-form-item label="上线" prop="isonline" class="text-center">
            <el-switch v-model="postForm.isonline" :active-value="1" :inactive-value="0" />
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item label="可分享" prop="isshare" class="text-center">
            <el-switch v-model="postForm.isshare" :active-value="1" :inactive-value="0" />
          </el-form-item>
        </el-col>
        <!-- <el-col :span="2">
          <el-form-item label="列表显示" prop="islistshow" class="text-center">
            <el-switch v-model="postForm.islistshow" :active-value="1" :inactive-value="0" />
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item label="分享礼" prop="ismeetingsharegift" class="text-center">
            <el-switch v-model="postForm.ismeetingsharegift" :active-value="1" :inactive-value="0" />
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item label="邀请码邀约" prop="ismeetingcodeinvite" class="text-center">
            <el-switch v-model="postForm.ismeetingcodeinvite" :active-value="1" :inactive-value="0" />
          </el-form-item>
        </el-col> -->
        <el-col :span="2">
          <el-form-item label="内部测试" prop="isTest" class="text-center">
            <el-switch v-model="postForm.isTest" :active-value="1" :inactive-value="0" />
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item label="HCPE" prop="isHcpe" class="text-center">
            <el-switch v-model="postForm.isHcpe" :active-value="1" :inactive-value="0" />
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item label="HT" prop="ht" class="text-center">
            <el-switch v-model="postForm.ht" :active-value="1" :inactive-value="0" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20" class="mt30">
        <el-col :span="18" :offset="3">
          <el-form-item>
            <el-button type="primary" @click="submitForm">提 交</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
// import VueUeditorWrap from 'vue-ueditor-wrap'
import { mapGetters } from 'vuex'
import {
  getProvince,
  getCities,
  getDepartments,
  getBroadcasts,
  getBuList,
  getTaList,
  getProducts,
  getUserType
} from '@/api/baseData'
import {
  getMeetingShow,
  // getAllMeetingsList,
  getMeetingType,
  getJoinMeetingType,
  addMeeting,
  editMeeting
} from '@/api/meetings'

const defaultForm = {
  id: undefined,
  meetingtitle: '',
  lecturerName: [],
  type: '',
  meetingtype: '',
  dateRange: [],
  begintime: '',
  endtime: '',
  actualDateRange: [],
  actualBeginTime: '',
  actualEndTime: '',
  meetingcode: '',
  omcode: '',
  province: '',
  provinceCode: '',
  city: '',
  cityCode: '',
  location: '',
  // parentmeetingid: '',
  // relatedmeetingid: '',
  livebroadcastid: '',
  isonline: 0,
  isshare: 0,
  // islistshow: 0,
  // ismeetingsharegift: 0,
  // ismeetingcodeinvite: 0,
  isTest: 0,
  isHcpe: 0,
  coverurl: '',
  icon: '',
  backgroundpictureurl: '',
  meetingdesc: '',
  buids: [],
  taids: [],
  brandids: [],
  departids: [],
  userTypeids: [],
  thirdUrl: '',
  isThird: 0,
  ht: 0
  // livebroadcastschedule: ''
}

export default {
  name: 'MeetingForm',
  // components: {
  //   VueUeditorWrap
  // },
  props: {
    isEdit: {
      type: Boolean,
      default: false
    }
  },
  data() {
    const validateBroadcast = (rule, value, callback) => {
      if (this.postForm.livebroadcastid === '' && this.postForm.meetingtype === 2) {
        callback(new Error('请选择会议直播'))
      } else {
        callback()
      }
    }
    const validateCity = (rule, value, callback) => {
      if (this.postForm.cityCode === '' && this.postForm.meetingtype === 1) {
        callback(new Error('请选择省份城市'))
      } else {
        callback()
      }
    }
    const validateThirdLink = (rule, value, callback) => {
      if (this.postForm.thirdUrl === '' && this.postForm.isThird === 1) {
        callback(new Error('请输入活动页面地址'))
      } else {
        callback()
      }
    }

    return {
      meetingTypeOptions: [],
      joinMeetingTypeOptions: [],
      // parentMeetingOptions: [],
      provinceOptions: [],
      cityOptions: [],
      relatedMeetingOptions: [],
      broadcastsOptions: [],
      buListOptions: [],
      taListOptions: [],
      productsOptions: [],
      coverList: [],
      iconList: [],
      backgroundList: [],
      deparpmentOptions: [],
      userTypeOptions: [],
      // dateRange: [],
      postForm: Object.assign({}, defaultForm),
      loading: false,
      rules: {
        meetingtitle: [
          { required: true, message: '请输入会议标题', trigger: 'blur' },
          { min: 1, max: 50, message: '长度在 1 到 50 个字', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择会议类型', trigger: 'change' }
        ],
        meetingtype: [
          { required: true, message: '请选择参会类型', trigger: 'change' }
        ],
        provinceCode: [
          { validator: validateCity }
        ],
        cityCode: [
          { validator: validateCity }
        ],
        // departids: [
        //   { required: true, message: '请选择目标科室', trigger: 'change' }
        // ],
        dateRange: [
          { required: true, message: '请选择会议起止时间', trigger: 'change' }
        ],
        livebroadcastid: [
          { validator: validateBroadcast }
        ],
        thirdUrl: [
          { validator: validateThirdLink }
        ]
      },
      // ueditorConfig: {
      //   // 编辑器不自动被内容撑高
      //   autoHeightEnabled: false,
      //   // 初始容器高度
      //   initialFrameHeight: 300,
      //   // 初始容器宽度
      //   initialFrameWidth: '100%',
      //   // 上传文件接口
      //   serverUrl: process.env.VUE_APP_BASE_API + '/config',
      //   // UEditor 资源文件的存放路径，vuecli2放在static目录无需配置以下，vuecli3放在public目录，需配置
      //   UEDITOR_HOME_URL: '/UEditor/'
      // },
      uploadUrl: process.env.VUE_APP_BASE_API + '/content/imgUpload'
    }
  },
  computed: {
    ...mapGetters([
      'token'
    ]),
    isBroadcastMeeting() {
      return this.postForm.meetingtype === 2
    },
    isCityMeeting() {
      return this.postForm.meetingtype === 1
    },
    checkThirdPage() {
      return this.postForm.isThird === 1
    }
  },
  created() {
    this.fetchMeetingType()
    this.fetchJoinMeetingType()
    this.fetchProvince()
    // this.fetchMeetingsList()
    this.fetchBroadcasts()
    this.fetchtBuList()
    this.fetchtTaList()
    this.fetchtProducts()
    this.fetchDepartments()
    this.fetchUserType()
    this.postForm.dateRange = []
    this.postForm.actualDateRange = []
    if (this.isEdit) {
      const id = this.$route.params && this.$route.params.id
      this.fetchData(id)
    }
  },
  methods: {
    fetchMeetingType() {
      getMeetingType().then(response => {
        // console.log(response)
        this.meetingTypeOptions = response.data
      }).catch(err => {
        console.log(err)
      })
    },
    fetchJoinMeetingType() {
      getJoinMeetingType().then(response => {
        // console.log(response)
        this.joinMeetingTypeOptions = response.data
      }).catch(err => {
        console.log(err)
      })
    },
    // fetchMeetingsList() {
    //   getAllMeetingsList().then(response => {
    //     // console.log(response)
    //     this.parentMeetingOptions = response.data
    //     this.relatedMeetingOptions = response.data
    //   }).catch(err => {
    //     console.log(err)
    //   })
    // },
    fetchBroadcasts() {
      getBroadcasts().then(response => {
        // console.log(response)
        this.broadcastsOptions = response.data
      }).catch(err => {
        console.log(err)
      })
    },
    fetchProvince() {
      getProvince().then(response => {
        // console.log(response)
        this.provinceOptions = response.data
      }).catch(err => {
        console.log(err)
      })
    },
    fetchCities(code) {
      getCities({ provinceCode: code }).then(response => {
        // console.log(response)
        this.cityOptions = response.data
      }).catch(err => {
        console.log(err)
      })
    },
    fetchtBuList() {
      getBuList().then(response => {
        // console.log(response)
        this.buListOptions = response.data
      }).catch(err => {
        console.log(err)
      })
    },
    fetchtTaList() {
      getTaList().then(response => {
        // console.log(response)
        this.taListOptions = response.data
      }).catch(err => {
        console.log(err)
      })
    },
    fetchtProducts() {
      getProducts().then(response => {
        // console.log(response)
        this.productsOptions = response.data
      }).catch(err => {
        console.log(err)
      })
    },
    fetchDepartments() {
      getDepartments().then(response => {
        // console.log(response)
        this.deparpmentOptions = response.data
      }).catch(err => {
        console.log(err)
      })
    },
    fetchUserType() {
      getUserType().then(response => {
        // console.log(response)
        this.userTypeOptions = response.data
      }).catch(err => {
        console.log(err)
      })
    },
    fetchData(id) {
      getMeetingShow({ id }).then(response => {
        const { data } = response
        // console.log(data)
        this.coverList = []
        if (!this._.isEmpty(data.coverurl)) {
          this.coverList.push({
            name: 'uploadCover' + 0,
            url: data.coverurl
          })
        }
        this.iconList = []
        if (!this._.isEmpty(data.icon)) {
          this.iconList.push({
            name: 'uploadIcon' + 0,
            url: data.icon
          })
        }
        this.backgroundList = []
        if (!this._.isEmpty(data.backgroundpictureurl)) {
          this.backgroundList.push({
            name: 'detailImg' + 0,
            url: data.backgroundpictureurl
          })
        }
        this.postForm.id = data.id
        this.postForm.meetingtitle = data.meetingtitle
        this.postForm.lecturerName = data.lecturer
        this.postForm.type = data.type
        this.postForm.meetingtype = data.meetingtype
        this.postForm.begintime = data.begintime
        this.postForm.endtime = data.endtime
        this.postForm.dateRange.push(data.begintime, data.endtime)
        this.postForm.actualBeginTime = data.actualBeginTime
        this.postForm.actualEndTime = data.actualEndTime
        this.postForm.actualDateRange.push(data.actualBeginTime, data.actualEndTime)
        this.postForm.meetingcode = data.meetingcode
        this.postForm.omcode = data.omcode
        this.postForm.province = data.province
        this.postForm.provinceCode = data.provinceCode
        this.postForm.city = data.city
        this.postForm.cityCode = data.cityCode
        this.postForm.location = data.location
        // this.postForm.parentmeetingid = data.parentmeetingid
        // this.postForm.relatedmeetingid = data.relatedmeetingid
        this.postForm.livebroadcastid = data.livebroadcastid
        this.postForm.isonline = data.isonline
        this.postForm.isshare = data.isshare
        // this.postForm.islistshow = data.islistshow
        // this.postForm.ismeetingsharegift = data.ismeetingsharegift
        // this.postForm.ismeetingcodeinvite = data.ismeetingcodeinvite
        this.postForm.isTest = data.isTest
        this.postForm.isHcpe = data.isHcpe
        this.postForm.coverurl = data.coverurl
        this.postForm.icon = data.icon
        this.postForm.backgroundpictureurl = data.backgroundpictureurl
        this.postForm.meetingdesc = data.meetingdesc
        this.postForm.departids = data.departids
        this.postForm.brandids = data.brandids
        this.postForm.userTypeids = data.userTypeids
        this.postForm.thirdUrl = data.thirdUrl
        this.postForm.isThird = data.isThird
        this.postForm.ht = data.ht
        this.postForm.taids = data.taids
        this.postForm.buids = data.buids
        // this.postForm.livebroadcastschedule = data.livebroadcastschedule

        if (!this._.isEmpty(data.provinceCode)) {
          this.fetchCities(data.provinceCode)
        }
        // console.log(this.coverList)
      }).catch(err => {
        console.log(err)
      })
    },
    handleUploadRemove(file) {
      // console.log(file)
      const index = this.coverList.indexOf(file)
      if (index !== -1) {
        this.coverList.splice(index, 1)
        this.postForm.coverurl = ''
      }
    },
    handleUploadSucc(res) {
      // console.log(res)
      res.data.forEach((item, index) => {
        if (this.coverList.indexOf(item) === -1) {
          this.postForm.coverurl = item
          this.coverList.push({
            name: 'uploadCover' + index,
            url: item
          })
        }
      })
    },
    handleIconUploadRemove(file) {
      // console.log(file)
      const index = this.iconList.indexOf(file)
      if (index !== -1) {
        this.iconList.splice(index, 1)
        this.postForm.icon = ''
      }
    },
    handleIconUploadSucc(res) {
      // console.log(res)
      res.data.forEach((item, index) => {
        if (this.iconList.indexOf(item) === -1) {
          this.postForm.icon = item
          this.iconList.push({
            name: 'iconImg' + index,
            url: item
          })
        }
      })
    },
    handleBgUploadRemove(file) {
      // console.log(file)
      const index = this.backgroundList.indexOf(file)
      if (index !== -1) {
        this.backgroundList.splice(index, 1)
        this.postForm.backgroundpictureurl = ''
      }
    },
    handleBgUploadSucc(res) {
      // console.log(res)
      res.data.forEach((item, index) => {
        if (this.backgroundList.indexOf(item) === -1) {
          this.postForm.backgroundpictureurl = item
          this.backgroundList.push({
            name: 'detailImg' + index,
            url: item
          })
        }
      })
    },
    dateRangeChange(date) {
      // console.log(date)
      if (!this._.isEmpty(date)) {
        this.postForm.begintime = date[0]
        this.postForm.endtime = date[1]
        this.postForm.dateRange = date
      } else {
        this.postForm.begintime = ''
        this.postForm.endtime = ''
        this.postForm.dateRange = []
      }
    },
    actualDateRangeChange(date) {
      // console.log(date)
      if (!this._.isEmpty(date)) {
        this.postForm.actualBeginTime = date[0]
        this.postForm.actualEndTime = date[1]
        this.postForm.actualDateRange = date
      } else {
        this.postForm.actualBeginTime = ''
        this.postForm.actualEndTime = ''
        this.postForm.actualDateRange = []
      }
    },
    changeProvince(province) {
      this.postForm.city = ''
      this.postForm.cityCode = ''
      this.cityOptions = []
      if (this._.isEmpty(province)) {
        this.postForm.province = ''
      } else {
        let provinceObj = {}
        provinceObj = this.provinceOptions.find((item) => {
          return item.province_code === province
        })
        this.postForm.province = provinceObj.province_name
        this.fetchCities(province)
      }
    },
    changeCity(city) {
      if (this._.isEmpty(city)) {
        this.postForm.city = ''
      } else {
        let cityObj = {}
        cityObj = this.cityOptions.find((item) => {
          return item.city_code === city
        })
        this.postForm.city = cityObj.city_name
      }
    },
    submitForm() {
      this.$refs.postForm.validate(valid => {
        if (valid) {
          this.postForm.lecturerName = this.postForm.lecturerName.join(',')
          this.postForm.departids = this.postForm.departids.join(',')
          this.postForm.buids = this.postForm.buids.join(',')
          this.postForm.taids = this.postForm.taids.join(',')
          this.postForm.brandids = this.postForm.brandids.join(',')
          this.postForm.userTypeids = this.postForm.userTypeids.join(',')

          this.loading = true
          if (this.isEdit) {
            editMeeting(this.postForm).then(response => {
              // console.log(response)
              this.$notify({
                title: '成功',
                message: '编辑会议成功',
                type: 'success',
                duration: 2000
              })
              this.loading = false
              this.$router.go(-1)
            }).catch(err => {
              console.log(err)
            })
          } else {
            addMeeting(this.postForm).then(response => {
              // console.log(response)
              this.$notify({
                title: '成功',
                message: '添加会议成功',
                type: 'success',
                duration: 2000
              })
              this.loading = false
              this.$router.go(-1)
            }).catch(err => {
              console.log(err)
            })
          }
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm() {
      this.$refs.postForm.resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
.create-post-container {
  position: relative;
}
</style>
